package com.topscore.uke.mvp.model;

import com.topscore.uke.mvp.contractors.PostBodyDataContractor;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.network.request.PostBodyDataRequest;
import com.topscore.uke.network.retrofit.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 71468 on 2017/10/20.
 */

public class PostBodyDataModel implements PostBodyDataContractor,PostBodyDataContractor.Model {
    private Listener mListener;

    public PostBodyDataModel(Listener listener) {
        this.mListener = listener;
    }

    @Override
    public void postData(PostBodyDataRequest request) {
        mService.postBodyData(request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(mListener) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        mListener.onPostSuccess();
                    }
                });
    }
}
